package jdbc.util;

import java.sql.*;

public class JdbcUtil {

    private static Connection conn=null;
    public static Connection getconnection() {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/work", "root", "123456");
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }

    public static void colse(Connection con, PreparedStatement ps, ResultSet res) {
        if (res != null){
            try{
                res.close();
            }catch(SQLException e){
                e.printStackTrace();
            }
        }
        if (ps != null){
            try{
                ps.close();
            }catch(SQLException e){
                e.printStackTrace();
            }
        }
        if (conn != null){
            try{
                conn.close();
            }catch(SQLException e){
                e.printStackTrace();
            }
        }

    }
}
